<?php include "template_header.php"?>
		<title>Dang ky thanh vien</title>
		<meta charset="utf-8"> 
		<link rel="stylesheet" href="./DatePicker/jquery.ui.all.css"> 
		<script src="./DatePicker/jquery-1.5.1.js"></script> 
		<script src="./DatePicker/jquery.ui.core.js"></script> 
		<script src="./DatePicker/jquery.ui.widget.js"></script> 
		<script src="./DatePicker/jquery.ui.datepicker.js"></script> 
		<link rel="stylesheet" href="./DatePicker/demos.css"> 
		<script> 
		$(function() {
			$( "#datepicker" ).datepicker({ showOtherMonths:true, selectOtherMonths:true});
		});
		</script> 
		
		<script type="text/javascript">
		function check(str)
		{
			//   http://api.jquery.com/jQuery.ajax/
			//alert(document.getElementById('tendn').value);
			$.ajax({
				  url: "ajax.php",
				  type:"POST",
				  data: ({data : document.getElementById('tendn').value}),
				  dataType: "html",
				  success: function(x){
					alert(x);
					//document.getElementById('thongbao').value = "abc";
				    //$(this).addClass("done");
				  }
				});
		}
	
	</script>
	
	
		
		<form name="formDangKy" method="post">
			<table>
				<tr>
					<td>Ten Dang Nhap</td>
					<td><input type="text" name="txtTenDangNhap" id="tendn" onblur="check('test')"/><div id="thongbao">thong bao</div></td>
				</tr>
				<tr>
					<td>Mat Khau</td>
					<td><input type="text" name="txtMatKhau" /></td>
				</tr>
				<tr>
					<td>Ho Ten</td>
					<td><input type="text" name="txtHoTen" /></td>
				</tr>
				<tr>
					<td>Gioi Tinh</td>
					<td>
						Nam<input type="radio" name="phai" value="Nam" />
						
						Nu<input type="radio" name="phai" value="Nu" />
					</td>
				</tr>
				<tr>
					<td>Ngay Sinh</td>
					
					<td><input type="text" name="txtNgaySinh" id="datepicker" ></td> 
					
				</tr>
				<tr>
					<td>Dia Chi</td>
					<td><input type="text" name="txtDiaChi"  /></td>
				</tr>
				<tr>
					<td><input type="submit" name="btnDangKy" value="Dang ky" /></td>
				</tr>
			</table>
		</form>
		<?php
			if(count($_POST) == 0)
			{
				return;
			}
			else
			{
				$username = $_POST["txtTenDangNhap"];
				$password = $_POST["txtMatKhau"];
				$name = $_POST["txtHoTen"];
				$nam = 'unchecked';
				$nu = 'unchecked';
				if(isset($_POST["btnDangKy"]))
				{
					$selected_radio = $_POST["phai"];
					if($selected_radio == 'Nam')
					{
						//$nam = 'checked';
						$phai = 1;
					}
					else
					{
						//$nu = 'checked';
						$phai = 0;
					}
				}
				$ngaysinh = $_POST["txtNgaySinh"];
				$address = $_POST["txtDiaChi"];

				echo ($username);
				echo ($password);
				echo ($name);
				echo ($selected_radio);
				echo ($ngaysinh);
				echo ($address);
				$connection = mysql_connect("localhost","root","truchung") or ("couldn't connect to localhost");
				mysql_select_db("dangnhap", $connection);
				mysql_query("set names 'utf8'");
				$sql = "insert into DangNhap (TenDangNhap, MatKhau, HoTen, GioiTinh, NgaySinh, DiaChi) values ('".$username."', '".$password."', '".$name."' , ". $phai.", ". $ngaysinh.", '".$address."')";
				echo $sql;
				$result = mysql_query($sql, $connection);
				mysql_close($connection);
			}
		?>
		<a href="DangNhap.php">Log in</a>

<?php include "template_footer.php"?>